home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / set80.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-10  |  5.6 KB  |  203 lines

  1. /*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  2.  *
  3.  *  Copyright (C) 1995,1996  Koen Gadeyne
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20.  
  21. /***
  22.  *** set80: sets your VGA card back to 80x25. Useful in case SVGATextMode screws up.
  23.  ***        it will also resize the VT's (when the kernel supports it), but only the first 16 active ones
  24.  ***        Any "special" features that need a TextConfig file are not implemented.
  25.  ***        It is intended to run completely stand-alone.
  26.  ***
  27.  *** Does NOT work for all cards. Those that use EXTENSION bits in addition to the two 
  28.  *** "standard" VGA ones for clock selection, instead if a completely different set of bits
  29.  *** (and then using clock index 2 or 3 to point the VGA chip to the "other" clock selection method)
  30.  *** will probably NOT switch back to the correct clock... 
  31.  *** ATI chips are an example of this.
  32.  ***/
  33.  
  34. /* #define USE_SVGALIB */
  35.  
  36. /* if "-a" option defined, use register dump instead of specific register
  37.    programming. A register dump is "safer" because it restores ALL standard
  38.    VGA registers to a known state, so there is more chance of getting a good
  39.    textmode back from it. A specific register programming method changes
  40.    only those registers that need to be changed, and thus less chance of
  41.    changing something that should not be changed...
  42. */
  43.  
  44. #ifdef DOS
  45. #  define NO_RESIZE
  46. #endif
  47.  
  48. #include "misc.h"
  49. #include "ttyresize.h"
  50. #include <unistd.h>
  51. #include <stdio.h>
  52. #ifndef DOS
  53. #  include <sys/ioctl.h>
  54. #  include <sys/kd.h>
  55. #endif
  56. #include "vga_prg.h"
  57. #include "setclock.h"
  58. #include "std_clock.h"
  59. #include "messages.h"
  60. #include "textregs.h"
  61.  
  62. #ifdef USE_SVGALIB
  63. #include <vga.h>
  64. #endif
  65.  
  66.  
  67. /*
  68.  * This mode line will be programmed. It is not used by set80, it's just informational
  69.  */
  70. #define MODELINE "80x25x9" 28.3      640 680 776 800      400 412 414 449   font 9x16
  71.  
  72.  
  73. /*
  74.  * global variables
  75.  */
  76.  
  77. char *CommandName;
  78. bool debug_messages=FALSE;
  79.  
  80. int STM_Options=0;  /* just to keep the compiler happy */
  81. t_terminals *p_terminals=NULL; /* ditto */
  82.  
  83. void usage()
  84. {
  85.      PMESSAGE(("version %s. (c) 1995,1996 Koen Gadeyne.\n\n\
  86.      Resets and resizes the console to 80x25 mode, with a 9x16 font.\n\
  87.      It is completely stand-alone (does not call other programs, no config file).\n\n\
  88.      Options: -d  print debugging messages\n\
  89.               -h  prints usage information\n\
  90.               -a  use alternate method: restore ALL standard VGA registers.\n",
  91.      VERSION, CommandName));
  92. }
  93.  
  94.  
  95. /****************************************************************************************************************************/
  96.  
  97. int main (int argc, char* argv[])
  98. {
  99.   int c;
  100.   bool restore_all_regs=FALSE;
  101.   int i;
  102.  
  103.   CommandName = argv[0];
  104.  
  105.   while ((c = getopt (argc, argv, "hda")) != EOF)
  106.     switch (c)
  107.     {
  108.       case 'd': debug_messages=TRUE;
  109.                 break;
  110.       case 'a': restore_all_regs=TRUE;
  111.                 break;
  112.       case 'h': usage();
  113.                 exit(0);
  114.                 break;
  115.       case '?': usage();
  116.                 PERROR(("Bad option '-%c'\n",(char)optopt));
  117.                 exit(-1);
  118.                 break;
  119.       default: PERROR(("getopt returned unknown token '%c'.\n",c));
  120.     }
  121.  
  122.   PVERSION;
  123.  
  124. #ifndef DOS
  125. #  ifdef NO_RESIZE
  126.     if (check_if_resize(80, 25))
  127.        PWARNING(("Screen resizing was not compiled in (NO_RESIZE defined when compiling).\n\
  128.         Your screen will be garbled, but hopefully useful...\n"));
  129. #  else
  130.     /* we don't check if resizing is necessary: just do it ALWAYS. You never know */
  131.     if (!check_kernel_version(1,1,54, "Virtual Terminal resizing"))
  132.       PWARNING(("Screen resizing not supported by this kernel version.\n\
  133.          Your screen will be garbled, but hopefully useful...\n"));
  134.     else
  135.     {
  136.       do_VT_RESIZE(80, 25, TRUE);  /* always allow going via a 1x1 screen. This is a resque program */
  137.       resize_active_vts(80, 25);
  138.     }
  139. #  endif
  140. #else
  141.    resize_DOS(80, 25);
  142. #endif
  143.  
  144.  
  145.  
  146. #ifndef USE_SVGALIB
  147.  
  148.   get_VGA_io_perm(CS_VGA);
  149.  
  150.   outb(0x00, 0x3CC);
  151.   outb(0x01, 0x3CA);
  152.  
  153.   unlock(CS_VGA);
  154.   
  155.   if (restore_all_regs) 
  156.   {
  157.     outb(TXT_MISC_REG, VGA_MISC_W);
  158.     SYNCRESET_SEQ;
  159.     for (i=0 ; i<NUM_STD_SEQ_REGS; i++) Outb_SEQ(i, TXT_SEQ_REGS[i]);
  160.     ENDRESET_SEQ;
  161.     for (i=0 ; i<NUM_STD_CRTC_REGS; i++) Outb_CRTC(i, TXT_CRTC_REGS[i]);
  162.     for (i=0 ; i<NUM_STD_GRCTL_REGS; i++) Outb_GR_CTL(i, TXT_GRCTL_REGS[i]);
  163.     for (i=0 ; i<NUM_STD_ATRCTL_REGS; i++) Outb_ATR_CTL(i, TXT_ATRCTL_REGS[i]);
  164.     for (i=0 ; i<256; i++) WRITERGB(i, STD_PALETTE[i][0], STD_PALETTE[i][1], STD_PALETTE[i][2]);
  165.   }
  166.   else
  167.   {
  168.     Set_MAX_SCANLINE (16);
  169.       
  170.     set_V_timings(400, 412, 414, 449);
  171.     set_H_timings(640, 680, 776, 800);
  172.  
  173.     Set_CURSOR_START(16-2) ; Set_CURSOR_END(16-1);
  174.  
  175.     Set_HSYNC_POLARITY(NEG) ; Set_VSYNC_POLARITY(POS);
  176.  
  177.     Set_Textmode;
  178.  
  179.     set_charwidth(9);
  180.     
  181.     SET_CLOCKBITS_0_1(1);   /* select standard VGA 28 MHZ clock */
  182.     usleep(50000);
  183.  
  184.     SCREEN_ON;
  185.  
  186.   }
  187.   
  188.   
  189. #ifndef DOS
  190.   ioctl(opentty("/dev/console"), KDSETMODE, KD_TEXT);
  191. #endif
  192.   
  193. #else  
  194.  
  195. vga_setmode(TEXT);
  196.  
  197. #endif
  198.   return(0);
  199.  
  200. }
  201.  
  202.  
  203.